package web1.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import web1.bean.Group;
import web1.bean.user;

/**
 * Servlet implementation class jstl
 */
@WebServlet("/s/jstl")
public class jstl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public jstl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		//普通字符串
		request.setAttribute("hello","hello world");
		//html字符串
		request.setAttribute("welcome", "<font color='red'>欢迎光临</font>");
		//条件控制标签
		request.setAttribute("v1", 10);
		request.setAttribute("v2", 20);
		request.setAttribute("userList", new ArrayList());
		
		//结构
		Group group = new Group();
        group.setName("提高班第八期");
                
        List users = new ArrayList();
        for (int i=0; i<10; i++) {
                user u = new user();
                u.setName("xh(" + i+")");
                u.setAge(18 + i);
                u.setGroup(group);
                users.add(u);
        }
        request.setAttribute("users", users);
              
        //map
        Map map=new HashMap();
        map.put("key1", "value1");
        map.put("key2", "value2");
        map.put("key3", "value3");
        map.put("key4", "value4");
        request.setAttribute("map", map);
                
        //forTokens
        request.setAttribute("strTokens", "1#2#3#4#5");        
        request.getRequestDispatcher("/day0905/jstl.jsp").forward(request, response);
        
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
